package com.hbmcc.rxjava.chapter01.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.hbmcc.rxjava.R
import com.hbmcc.rxjava.chapter01.adapter.base.SubAdapter
import com.hbmcc.rxjava.chapter01.holder.BannerViewHolder
import com.hbmcc.rxjava.chapter01.holder.PagerHolder

/**
 * 创建日期：2020/11/11
 * 描述:Banner Adapter
 * 作者:支豪亮
 */

val listItems = mutableListOf(
    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605105541302&di=e4fcd95bcf421d159b89def3f35480fa&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fa%2F581da421e68d2.jpg",
    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605105541302&di=6e692f88c7c401cf1f2b227a1fe099df&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Ff%2F58268ef72d580.jpg",
    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605105541301&di=fb8add96f8d84ab9cc9c07d13fab6296&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F5%2F587f26e34dba5.jpg",
)
class ProxyBannerAdapter(
    override val layoutId: Int,
    private val pool: RecyclerView.RecycledViewPool
) : SubAdapter<BannerViewHolder, String>(layoutId , null,null,1) {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        return BannerViewHolder(getBindView(parent))
    }

    override fun onBindProxyViewHolder(holder: BannerViewHolder, position: Int) {
        holder.itemViewPager.adapter = ProxyPagerItemAdapter(pool,
            object : SubAdapter<PagerHolder, String>(R.layout.view_pager_item, listItems, layoutHelper) {
                override fun onBindProxyViewHolder(holder: PagerHolder, position: Int) {
                    Glide.with(holder.itemView.context).load(listItems[position])
                        .into(holder.viewPagerItem)
                }

            })

        holder.itemViewPager.offscreenPageLimit = listItems.size
    }


}